package ca.jsbr.as2js_lib.display.canvas.view 
{
	import ca.jsbr.as2js_lib.display.canvas.CanvasStage;
	import ca.jsbr.as2js_lib.display.canvas.View;
	import js.element.canvas.CanvasRenderingContext2D;
	/**
	 * ...
	 * @author jsbr [me@jsbr.ca]
	 */
	public class DebugView extends View
	{
		
		private var _cpt:int;
		private var _time:Number=0;
		private var _accuracy:int=10;
		private var _fps:Number = 0;
		private var _mouseEnable:Number = 0;
		private var _tfps:Number = 0;
		private var _tcpt:Number = 0;
		
		public function DebugView() 
		{
			//_accuracy *= 1000 / this.stage.fps;
		}
		
		override public function render(ctx:CanvasRenderingContext2D):void 
		{
			this._cpt++;
			if(this._cpt>=_accuracy)
			{
				var d = new Date();
				
				var t:Number = d.getTime() - _time;
				_time = d.getTime();
				_fps = ((1000/(t/_cpt)*100)>>0)/100;  //((this._cpt / (t / 1000) * 100) >> 0) / 1000;
				_cpt = 0;
				
				_tcpt++;
				_tfps+=_fps;
			}
			
			ctx.fillStyle = "#FFFFFF";
			ctx.globalAlpha = 0.9;
			ctx.fillRect(1,   1, 100, 28);
			ctx.fill();
			ctx.textBaseline = 'top';
			ctx.font = "normal normal 9px Sans-serif";
			ctx.globalAlpha = 1;
			ctx.fillStyle = "#000000";
			ctx.textAlign = "left";
			ctx.fillText("fps : " + _fps + "/" + CanvasStage.instance.stageDescription.fps, 2, 2);
			ctx.fillText("moyenne : " + (((_tfps / _tcpt * 100) >> 0) / 100), 2, 12);
			ctx.fill();
		}
		
		public function get mouseEnable():Number 
		{
			return _mouseEnable;
		}
		
		public function set mouseEnable(value:Number):void 
		{
			_mouseEnable = value;
		}
		
	}

}